#ifndef AZMODEL_H
#define AZMODEL_H

#include <QAbstractItemModel>


#include "Az.h"

class AzRecord;
class AzRootRecord;
class AzAbstractDataSource;


class AZLIB_EXPORT AzModel : public QAbstractItemModel {
Q_OBJECT
public:
	AzModel(QObject * = 0);
	~AzModel();

	QModelIndex	parent(const QModelIndex & index) const;
	QModelIndex index(int row, int column, const QModelIndex & parent) const;
	int rowCount(const QModelIndex & parent = QModelIndex()) const;
	int	columnCount(const QModelIndex& parent = QModelIndex()) const;
	QVariant data(const QModelIndex & index, int role) const;
	bool setData(const QModelIndex & index, const QVariant & value, int role = Qt::EditRole);
	QVariant headerData(int section, Qt::Orientation orientation, int role) const;
	Qt::ItemFlags flags(const QModelIndex & index) const;

    AzAbstractDataSource *dataSource() const;
    void setDataSource(AzAbstractDataSource* source);

    const AzRecord* record(const QModelIndex &) const;
    AzRecord* record(const QModelIndex &);

    bool isOpen() const         { return mIsOpen; }
    bool open();
    void close();
signals:
    void calcField(const QModelIndex&,QVariant&) const;
protected:
private slots:
    void sourceDestroyed();
private:
	AzRootRecord *mRootRec;
    AzAbstractDataSource* mDataSource;
    bool mIsOpen;
};

#endif //AZMODEL_H
